﻿@using MvcForum.Core
@using MvcForum.Core.Constants
@using MvcForum.Web.Application.ExtensionMethods
@model MvcForum.Web.ViewModels.Admin.MemberListViewModel
@{
    ViewBag.Title = "Members";
}

<div class="panel">
    <div class="panel-heading">
        <h5>@ViewBag.Title</h5>
    </div>
    <div class="panel-content">
        @using (Html.BeginForm("Manage", "Account", FormMethod.Post))
        {
            <div class="input-group membersadminsearch">
                @Html.TextBoxFor(x => Model.Search, new { @class = "form-control" })
                <span class="input-group-btn">
                    <button class="btn btn-default" type="submit">Search</button>
                </span>
            </div>
            @Html.HiddenFor(x => x.PageIndex)
        }

        <table class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th>Edit</th>
                    <th>Users</th>
                    <th>Approved</th>
                    <th>Locked Out</th>
                    <th>Roles</th>
                    <th>Delete</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var user in Model.Users)
                {
                    var disabled = user.Id == Model.Id;

                    <tr>
                        <td>
                            <a href="@Url.Action("Edit", new { user.Id })" class="btn-mvc">
                                <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
                            </a>
                        </td>
                        <td>
                            <strong>@Html.DisplayFor(modelItem => user.UserName)</strong>
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => user.IsApproved)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => user.IsLockedOut)
                        </td>
                        <td>
                            <span class="listrolecbholder">
                                @foreach (var role in @Model.AllRoles)
                                {
                                    var showChecked = user.Roles.Contains(role.RoleName) ? "checked='checked'" : "";
                                    var disablecb = disabled ? "disabled='disabled'" : "";
                                    <span class="listrolecb">
                                        <input type="radio" name="Roles-@user.Id" value="@role.RoleName" @showChecked @disablecb /> @Html.Raw(role.RoleName)
                                    </span>
                                }
                                <input type="hidden" id="userId" value="@user.Id" />
                            </span>
                        </td>
                        <td>
                            @if (!disabled)
                            {
                                <a href="@Url.Action("Delete", new { user.Id, p = Model.PageIndex, search = Model.Search})" class="btn-mvc">
                                    <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                                </a>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>


        @if (Model.TotalPages > 1)
        {
            @Html.Pager(Convert.ToInt32(Model.PageIndex), ForumConfiguration.Instance.AdminListPageSize, Convert.ToInt32(Model.TotalCount), new { search = Model.Search })
        }

    </div>
</div>


